package com.tencent.wxpay.demo.service.impl;

import com.tencent.wxpay.WXPay;
import com.tencent.wxpay.demo.listener.ResultListener;
import com.tencent.wxpay.demo.service.CloseOrderService;
import com.tencent.wxpay.demo.util.TestUtil;
import com.tencent.wxpay.protocol.request.CloseOrderReqData;
import com.tencent.wxpay.protocol.response.CloseOrderResData;
import org.springframework.stereotype.Service;

@Service
public class CloseOrderServiceImpl implements CloseOrderService {

    @Override
    public CloseOrderResData doCloseOrder(String outTradeNo) {
        try{
            CloseOrderReqData closeOrderReqData = new CloseOrderReqData(outTradeNo);
            CloseOrderResData closeOrderResData = WXPay.doCloseOrderBusiness(closeOrderReqData,new ResultListener<CloseOrderResData>());
            return closeOrderResData;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        if(TestUtil.init()){
            try{
                CloseOrderService closeOrderService = new CloseOrderServiceImpl();
                CloseOrderResData closeOrderResData = closeOrderService.doCloseOrder("20161014105955");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
